<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/layui.js" charset="utf-8"></script>
</head>

<body>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-lg-offset3" layui-col-lg6>
                <div class="layui-form layuimini-form">
                    <form class="layui-form" action="" lay-filter="userForm">
                    
                        <!-- <input type="hidden" name="id" value="" class="layui-input"> -->
    
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" required lay-verify="required" placeholder="请输入商品名称"
                                       autocomplete="off" class="layui-input">
                            </div>
    
                        </div>
    
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品类型：</label>
                            <div class="layui-input-block">
                                <input type="text" name="type" required lay-verify="required" placeholder="请输入商品类型"
                                       autocomplete="off" class="layui-input">
                            </div>
    
                        </div>
    
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品发货地：</label>
                            <div class="layui-input-block">
                                <input type="text" name="address" required lay-verify="required" placeholder="请输入商品来源地"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">出库数量：</label>
                            <div class="layui-input-block">
                                <input type="text" name="number" required lay-verify="required" placeholder="请输入商品来源地"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
    
                        <div class="layui-form-item">
                            <label class="layui-form-label">负责人：</label>
                            <div class="layui-input-block">
                                <input type="text" name="manger" required lay-verify="required" placeholder="请输入负责人"
                                       autocomplete="off" class="layui-input">
                            </div>
    
                        </div>
    
                        <div class="layui-form-item">
                            <label class="layui-form-label">联系方式：</label>
                            <div class="layui-input-block">
                                <input type="text" name="phone" required lay-verify="required" placeholder="请输入联系方式"
                                       autocomplete="off" class="layui-input">
                            </div>
    
                        </div>
    
                        <div class="layui-inline">
                            <label class="layui-form-label">出库日期:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="date"  placeholder="yyyy-MM-dd" lay-verify="date"
                                       autocomplete="off" class="layui-input">  
                                       <!-- lay-verify="date" -->
                            </div>
                        </div>
    
    
    
    
    
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即出库</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
    
            </div>
        </div>
    </div>
    


<script>
    //Demo
    layui.use(['form','upload','element'], function () {
        // 表单对象  form
        var form = layui.form
            //jquery 对象 $
            , $ = layui.jquery
            ,element = layui.element
            ,upload = layui.upload
            // 日期组件
            , laydate = layui.laydate;

        //日期   渲染上面 id 为 date 的 标签
        laydate.render({
            elem: '#date'
        });

        // 从 localStorage 把数据取出来   并转成 js 对象
        //  JSON.parse("str")   把字符串转为 js 对象
        var data = JSON.parse(localStorage.getItem("student"));

        //给表单数据赋值
        form.val("userForm",{
            "id":data.id,
            "name":data.name,
            "type":data.type,
            "stock":data.stock

        });

        
        // token 前后端分离再用
       // var token = JSON.parse(localStorage.getItem("token"));


        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/outStorage/outstorageadd",
               // "headers":{"token":token},
                "data": data.field,
                // result 参数 表式后台响应的数据
                "success":function(result){
                    if(result.code == 200){

                        // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("添加成功");
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>